package xiyuan.localio;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import weibo4j.Users;
import weibo4j.model.User;
import weibo4j.model.WeiboException;

public class LocalWriter {

	public static void writeDistance(String dst, double distance, long uidF) throws IOException {

		//得到最终这个联系人的distance
		File disFile = new File(dst);
		Users um = new Users();
		String username = "";
		try {
			User user = um.showUserById(uidF + "");
			username = user.getName();
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		if (!disFile.exists()){
			disFile.createNewFile();
		}
		BufferedReader bufferedReader = new BufferedReader(  
                new FileReader(disFile));  
        StringBuilder stringBuilder = new StringBuilder(); 
        String string;
        while((string  = bufferedReader.readLine()) != null){  
            stringBuilder.append(string+"\r\n");  
        }
		FileWriter fw = new FileWriter(disFile);
		stringBuilder.append(uidF + "\t" + username + "\t" + distance + "\r\n");
		fw.write(stringBuilder.toString() + "\r\n");
		fw.close();
		
	}

}
